package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "购物车控制器")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    // 需求：清空购物车
    @DeleteMapping("/clean")
    public Result cleanCart(){
        log.info("[清空购物车]");
        shoppingCartService.cleanCart();
        return Result.success();
    }

    // 需求：获取购物车列表
    @GetMapping("/list")
    public Result<List<ShoppingCart>> findShoppingCartList(){
        log.info("[购物车列表]");
        List<ShoppingCart> shoppingCartList = shoppingCartService.findCartList();
        return Result.success(shoppingCartList);
    }


    // 需求添加购物车
    @PostMapping("/add")
    @ApiOperation("添加购物车接口")
    public Result addCart(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("[添加购物车] dto:{}",shoppingCartDTO);
        shoppingCartService.addCart(shoppingCartDTO);
        return Result.success();
    }
}
